<template>
	<div class="logined login-action">
        <div class="closelogin clearfix" >
            <a href="javascript:void(0)" @click=closelogin>×</a>
        </div>
        <h3>用户登录</h3>
        <form action="" autocomplete="on">
            <div class="com-login" >
                <input type="text" placeholder="用户名/手机号" id="username" v-model=username>
                <div class="closeusername display-none">×</div>
            </div>
            <div  class="com-login" style="margin-bottom:0">
                <input type="password" placeholder="密码" id="password" v-model=password @keyup.enter=denglu($event)>
                <div class="closepassword display-none">×</div>
            </div>
             <div style="height:30px"><p class="y-errorMsg" style="color:red;"></p></div>
            <button  @click="denglu" type="button" style="margin-top:0" >登录</button>
            <div class="forget">
                <a href="" class="fll ">忘记密码</a>
                <a href="javascript:void(0)" class="flr rightNow" @click=rightNow>注册账号></a>
            </div>
            <!--<div class="yixia clearfix">
                <span class="fll"></span>
                <i>使用以下方式登录</i>
                <span class="flr"></span>
            </div>
            <div class="three clearfix">
                <div>
                    <img src="${qq}" alt="">
                </div>
                <div style="border-color: #78d94b;">
                    <img src="${weixin}" alt="">
                </div>
                <div  style="border-color: #fe7416;">
                    <img src="${weibo}" alt="">
                </div>
            </div> -->
        </form>
    </div>
</template>
<script>
	"use strict";

module['base-login'] = {
    template: template,
    props:['username','password'],
    methods: {
        //点击注册账号跳转到注册页面
        rightNow: function rightNow() {
            $(".logined").addClass("display-none");
            $(".register").css('display',"block")
            $(".login2").addClass("active");
            $(".login1").removeClass("active");
        },
        //关闭登录页面
        closelogin: function closelogin(e) {
            e.preventDefault();
            $(".logined").hide();
            $(".cover-box").hide();
        },
        //登录接口的触发事件
        denglu: function denglu() {
            var that = this;
            if (this.password == "") {
                $('.y-errorMsg').text("请输入密码");
            }
            if (this.uername == "") {
                $('.y-errorMsg').text("请输入用户名");
            }
            if (this.username == "" || this.password == "") {
                return;
            }
            base.request(base.api(40), { username: this.username, password: this.password }, function (d) {
                loginSuccess.call(that, d);
            }, function (d) {
                loginFail.call(that, d);
            }); //登录接口
        }
    }
};
function loginSuccess(data) {
    //登录接口返回成功
    sessionStorage.setItem("sid", data.sid);
    sessionStorage.setItem("username", this.username);
    $(".y-errorMsg").text("登录成功");
    this.ismycountshow = !this.ismycountshow;
    this.isLoginshow = !this.isLoginshow;
    //延迟一秒让登录框消失
    var that = this;
    setTimeout(function () {
        $("#login").hide();
        that.$router.go(0);
    }, 1000);
};
function loginFail(data) {
    //登录接口返回失败
    if (data.code == -1) {
        $(".y-errorMsg").text("" + data.msg + "");
        $("#password").val("");
    }
};
</script>